C #4.0 new features (2) named parameters, optional parameters for interoperation with COM
1. Introduction
C # (2.0) is a pure object-oriented language like Java. They all use overload rather than optional parameters. However, for other external
Named parameters and optional parameters in C,
The named parameters and optional parameters are new in C # framework 4.0.
1. Definitions and calls of common methods
Public void Demo1 (string x, int y) {// do something...} public void Main () {//
This is the first blog from a series of blog post which I'm planning to do on whet's new in Visual C #4.0
This is the first article in the series of Visual C #4.0 new features I plan to write.
Optional parameter (optional parameters)
Optional
Optional parameters, naming parameters, special types and features of. NET, optional. net
1. Optional and named Parameters1.1 optional parametersSyntax:[Modifier] return type method name (required parameter n, optional parameter n)Note:1. The
Many developers asked why the named parameters and optional parameters were not added to the C # language until now. From the usage of other languages, they are all good features, especially when there are a lot of parameters in the method, but many
Optional and named parameters features provide great convenience in some occasions, especially in office development, you can say goodbye to system. reflection. Missing. Here is a brief introduction to optional and named parameters in C #4.0.
The C #
1. A named parameter allows the caller to assign a value to the parameter by supplying its name, so that the position of the parameter is not important. Optional parameters allow you to assign values to certain parameters when you define them, and
The three parameters of this introduction are grammatical sugars . 4. Array parameters When declaring a method, add the params keyword before the parameter. Simplified parameter invocation for added readability.Usage:(1) used when the parameter
The named parameter and optional parameter are new features of the C # Framework 4.0.I. General method definition and invocationpublic void Demo1 (string x, int y) { //do something ...} public void Main () { //Call Demo1 ("similar",
In the previous blog post, I mentioned the new language features in C #4.0, the "optional parameter", but it is still not satisfied after being written. I still have some questions that I have not explained. As a result, I made some explorations and
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.